export const maskPhone = (phone: string) => {
  if (phone && phone.length == 11) {
    let s1 = phone.slice(0, 3);
    let s2 = phone.slice(7);
    return s1 + '****' + s2
  }
  return phone;
}


export const Wait = (timeout = 350) => {
  return new Promise(resolve => {
    setTimeout(resolve, timeout);
  });
}

export const isEmptyObject = (data: {} | null | undefined) => {
  if (data == null || data == undefined)
    return true;

  if (Object.keys(data).length > 0) {
    return false;
  }
  return true;

}


export const isPoneAvailable = (str) => {
  var myreg = /^[1][3,4,5,6,7,8,9][0-9]{9}$/;
  if (!myreg.test(str)) {
    return false;
  }
  return true;
}


var UUID = require('uuid');

export const getUUID = () => {
  var str = UUID.v1();
  return str.replace(/-/g, "");
}



/**
       *
       * @param dateStr yyyy-MM-dd HH:mm:ss
       * @returns {string}
       */
export const toDateFriendly = (dateStr: string) => {
  //af-测试可用
  if (!dateStr) {
    return ''
  }

  let dateTimeStamp = Date.parse(dateStr.replace(/-/gi, "/"));
  let minute = 1000 * 60;
  let hour = minute * 60;
  let day = hour * 24;
  let halfamonth = day * 15;
  let month = day * 30;
  let now = new Date().getTime();
  let diffValue = now - dateTimeStamp;
  if (diffValue < 0) {
    return '';
  }
  let monthC = diffValue / month;
  let weekC = diffValue / (7 * day);
  let dayC = diffValue / day;
  let hourC = diffValue / hour;
  let minC = diffValue / minute;
  let result = '';
  if (monthC >= 1) {
    result = "" + parseInt(monthC.toString()) + "月前";
  } else if (weekC >= 1) {
    result = "" + parseInt(weekC.toString()) + "周前";
  } else if (dayC >= 1) {
    result = "" + parseInt(dayC.toString()) + "天前";
  } else if (hourC >= 1) {
    result = "" + parseInt(hourC.toString()) + "小时前";
  } else if (minC >= 1) {
    result = "" + parseInt(minC.toString()) + "分钟前";
  } else
    result = "刚刚";
  return result;
}